package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.entity.SpuInfo;
import com.atguigu.gmall.product.service.SpuInfoService;
import com.atguigu.gmall.product.vo.SpuDataVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author lfy
 * @Description
 * @create 2023-07-14 9:00
 */
@RequestMapping("/admin/product")
@RestController
public class SpuRestController {


    @Autowired
    SpuInfoService spuInfoService;

    /**
     * 分页查询某个分类下的所有商品
     * @param c3Id
     * @return
     */
    @GetMapping("/{pn}/{ps}") //?category3Id=61
    public Result spuPage(@RequestParam("category3Id") Long c3Id,
                          @PathVariable("pn") Long pn,
                          @PathVariable("ps") Long ps){

        //分页查询
        Page<SpuInfo> page = spuInfoService.lambdaQuery()
                .eq(SpuInfo::getCategory3Id, c3Id)
                .page(new Page<>(pn, ps));


        return Result.ok(page);
    }


    @PostMapping("/saveSpuInfo")
    public Result saveSpuInfo(@RequestBody SpuDataVo dataVo){


        spuInfoService.saveSpuInfo(dataVo);

        return Result.ok();
    }
}
